package com.lilihub.miaosha.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.nio.charset.CoderMalfunctionError;

/**
 * @BelongsProject: miaosha
 * @BelongsPackage: com.lilihub.miaosha.common
 * @Author: LiYing
 * @CreateTime: 2021-04-22 10:43
 * @Description:
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CodeMsg {

    //通用的错误码
    public static CodeMsg SUCCESS = new CodeMsg(0,"success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100,"服务端异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(500101,"参数校验异常：%s");
    public static CodeMsg REQUEST_ILLEAL = new CodeMsg(500102,"请求非法");
    public static CodeMsg ACCESS_LIMIT_REACHED = new CodeMsg(500103,"访问达到极限");


    //登录模块5002xx
    public static CodeMsg SESSION_ERROR = new CodeMsg(500210,"session不存在或者已经失效");
    public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211,"用户密码不能为空");
    public static CodeMsg PHONE_EMPTY = new CodeMsg(500212,"用户手机号不能为空");
    public static CodeMsg PHONE_ERROR = new CodeMsg(500213,"用户手机号格式错误");
    public static CodeMsg USER_EMPTY = new CodeMsg(500214,"用户不存在");
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215,"用户密码输入错误");

    //商品模块5003xx



    //订单模块5004xx
    public static CodeMsg ORDER_EMPTY = new CodeMsg(500400,"订单不存在");


    //秒杀模块5005xx
    public static CodeMsg MIAO_SHA_OVER = new CodeMsg(500500,"商品秒杀完毕");
    public static CodeMsg REPEATE_MIAOSHA = new CodeMsg(500501,"不能重复秒杀");
    public static CodeMsg MIAOSHA_FAIL = new CodeMsg(500502,"秒杀失败");


    private int code;
    private String msg;


    public CodeMsg fillArgs(Object... args){

        int code = this.code;

        String message = String.format(this.msg,args);

        return new CodeMsg(code,message);
    }

}
